/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PersonListPanel.java
 *
 * Created on Jul 12, 2011, 10:06:47 PM
 */
package panels;

import conn.EMIS4Connection;
import dao.PersonDao;
import java.awt.BorderLayout;
import java.sql.SQLException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import obj.Person;
import renderer.PersonListRenderer;

/**
 *
 * @author jm1156
 */
public class PersonListPanel extends javax.swing.JPanel {

    /** Creates new form PersonListPanel */
    public PersonListPanel(Person person) {
        initComponents();
        PersonListRenderer personListRenderer = new PersonListRenderer();
                
        EMIS4Connection connection = EMIS4Connection.getInstance();
        connection.connect();
        
        PersonDao personDao = new PersonDao();
        try {
            List list = personDao.searchMatching(connection.getConnection(), person);
            m_lstPersonList.setListData(list.toArray());
            m_lstPersonList.setCellRenderer(personListRenderer);
        } catch (SQLException ex) {
            Logger.getLogger(PersonListPanel.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public static void main(String [] args) {
        JFrame frame = new JFrame();
        frame.setLayout(new BorderLayout());
        
        Person person = new Person();
        person.setFirstName("Jason");
        
        PersonListPanel personListPanel = new PersonListPanel(person);
        frame.add(personListPanel);
        
        frame.setSize(500,500);
        frame.setVisible(true);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
  // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
  private void initComponents() {

    jScrollPane1 = new javax.swing.JScrollPane();
    m_lstPersonList = new javax.swing.JList();

    jScrollPane1.setName("jScrollPane1"); // NOI18N

    m_lstPersonList.setName("m_lstPersonList"); // NOI18N
    jScrollPane1.setViewportView(m_lstPersonList);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
    this.setLayout(layout);
    layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 396, Short.MAX_VALUE)
    );
    layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 296, Short.MAX_VALUE)
    );
  }// </editor-fold>//GEN-END:initComponents

  // Variables declaration - do not modify//GEN-BEGIN:variables
  private javax.swing.JScrollPane jScrollPane1;
  private javax.swing.JList m_lstPersonList;
  // End of variables declaration//GEN-END:variables

}